<?php
/*
This file is part of TEXTLOG.

TEXTLOG is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

TEXTLOG is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with TEXTLOG. If not, see http://www.gnu.org/licenses/.
*/

function textlog_wp_title() {
	$sep = '&middot;';
	if ( is_front_page() ) {
		$wp_title = sprintf( __( '%1$s %2$s %3$s', 'textlog'),
			wp_specialchars( get_bloginfo('name'), 1 ),
			$sep,
			wp_specialchars( get_bloginfo('description'), 1 )
		);
	} elseif ( is_home() ) {
		$wp_title = sprintf( __( 'Blog %1$s %2$s', 'textlog' ),
			$sep,
			wp_specialchars( get_bloginfo('name'), 1 )
		);
	} else {
		$wp_title = wp_title( $sep, false, 'right' ) . wp_specialchars( get_bloginfo('name'), 1 );
	}
	echo str_replace( array( "\r", "\n", "\t", "  " ), '', $wp_title );
}

function textlog_globalnav() {
	if ( $menu = str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages('title_li=&sort_column=menu_order&exclude=60,179&echo=0') ) )
		$menu = '<ul>' . $menu . '</ul>';
	$menu = '<div id="menu">' . $menu . "</div>\n";
	echo $menu;
}

// Echos the theme template style sheet links with absolute URIs
function textlog_css() {
	$cssdir = get_bloginfo('stylesheet_directory') . '/css';
	$css  = "\t" . '<link rel="stylesheet" type="text/css" href="' . $cssdir . '/main.css" media="screen,projection" />' . "\n";
	$css .= "\t" . '<link rel="stylesheet" type="text/css" href="' . $cssdir . '/thickbox.css" media="screen,projection" />' . "\n";
	$css .= "\t" . '<link rel="stylesheet" type="text/css" href="' . $cssdir . '/print.css" media="print" />' . "\n";
	echo $css;
}

// Echos the JavaScript with absolute URIs
function textlog_js() {
	$charset = get_bloginfo('charset');
	$jsdir = get_bloginfo('stylesheet_directory') . '/js';

	$js  = "\n<script type='text/javascript' src='$jsdir/jquery.pack.js'></script>";
	$js .= "\n<script type='text/javascript' src='$jsdir/thickbox.js'></script>";

	$js .= "\n<script type='text/javascript' charset='$charset'>
// <![CDATA[
$(document).ready(function(){
	$('div#menu ul li').hover(
		function(){ $('ul', this).fadeIn('fast'); },
		function(){ }
	);
	if (document.all) {
		$('div#menu ul li').hoverClass ('sfHover');
	}
	$('div.entry-content a.readme, div.entry-attachment a ').addClass('thickbox');
	$('div.entry-content a.readme').each(function(){
		$(this).attr( 'href', $(this).attr('href') + '?TB_iframe=true&amp;height=600&amp;width=600');
	});
	tb_init('div.entry-content a.readme, div.entry-attachment a');
});
$.fn.hoverClass = function(c){
	return this.each(function(){
		$(this).hover(
			function() { $(this).addClass(c); },
			function() { $(this).removeClass(c); }
		);
	});
};
// ]]>
</script>";

	echo $js;
}

// Enables localization, if applicable.
load_theme_textdomain('textlog');

// Filters the Sandbox globalnav content
add_filter( 'html_title', 'textlog_wp_title' );
add_filter( 'globalnav_menu', 'textlog_globalnav' );

// Filters the default style sheet link
add_action( 'wp_head', 'textlog_css', 1 );

// Adds our function to print JavaScript via wp_footer()
add_action( 'wp_footer', 'textlog_js', 1 );
?>